/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.chl.project.carshop07.core;


import java.io.Serializable;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author AMADIN
 */
@XmlRootElement
@Entity
public class OrderItem implements Serializable{

    private static final long serialVersionUID = 1L;
    @XmlAttribute
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;   
    private int quantity;
     
    @XmlElement(name = "car")
    @OneToOne (cascade = { CascadeType.PERSIST})
    //Bad hardcoded
    private Car product;
    
    public OrderItem() {  
     
    }
    public OrderItem(int quantity, Car product) {
        this.quantity = quantity;
        this.product = product;
    }
   
    @XmlTransient
    public Car getProduct() {
        return product;
    }

    public void setProduct(Car product) {
        this.product = product;
    }
    

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public double getCost() {
       return  quantity*product.getPrice();
    } 
    
    @XmlTransient
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof OrderItem)) {
            return false;
        }
        OrderItem other = (OrderItem) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "edu.chl.project.ws.core.OrderItem[ id=" + id + " ]";
    }    
}

